package demo4.service;

import demo4.dao.IUserDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserService implements IUserService{
    @Autowired
    private IUserDAO UserDAO;
    @Override
    public boolean login(String username, String password) {
        //首先根据用户名查询该用户信息
        System.out.println("UserService:根据用户名查询该校用户信息");
        boolean userinfo = UserDAO.finUserByName(username);
        if (userinfo) {//查询该用户
            //使用登录的密码和用户注册时的密码对比
            System.out.println("UserService:对比密码是否正确");
            if (Math.random()<0.5){
                System.out.println("UserService:密码正确，登录成功");
                return true;
            }
        }
        return false;
    }
}
